package store.lunangangster.engine.bpmn.parser.handler;

import store.lunangangster.bpmn.model.Event;
import store.lunangangster.bpmn.model.IntermediateCatchEvent;
import store.lunangangster.bpmn.model.definition.EventDefinition;
import store.lunangangster.bpmn.model.definition.TimerEventDefinition;
import store.lunangangster.engine.bpmn.parser.BpmnParser;
import store.lunangangster.engine.impl.bpmn.behavior.IntermediateCatchTimerEventBehavior;

public class IntermediateCatchEventParseHandler extends EventParseHandler<IntermediateCatchEvent> {

  @Override
  public void handle0(BpmnParser bpmnParser, IntermediateCatchEvent intermediateCatchEvent) {
    if (!intermediateCatchEvent.getEventDefinitions().isEmpty()) {
      EventDefinition eventDefinition = intermediateCatchEvent.getEventDefinitions().get(0);

      if (eventDefinition instanceof TimerEventDefinition) {
        TimerEventDefinition timerEventDefinition = (TimerEventDefinition) eventDefinition;
        intermediateCatchEvent.setBehavior(new IntermediateCatchTimerEventBehavior(timerEventDefinition));
      }
    }
  }

  @Override
  public Class<? extends Event> getType() {
    return IntermediateCatchEvent.class;
  }
}
